<template>

  <div>
      <el-card >
           <div slot="header" class="clearfix">
            <span style="line-height: 36px;">医疗保险责任</span>         
        </div>
        <el-form label-width="180px">
            <el-row>  
          <el-col :span="12">
            <el-form-item label="保险金额">
              <el-input v-model="INTEREST_PRODUCE.INTEREST_PRODUCE_MAXMONEY" placeholder="保险金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="自付比例金额上限">
              <el-input v-model="INTEREST_PRODUCE.INTEREST_PRODUCE_ZFMAX" placeholder="自付比例金额上限"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
         <el-row >
          <el-col :span="12">
            <el-form-item label="免赔额单次/累计">
              <el-radio-group v-model="INTEREST_PRODUCE.INTEREST_PRODUCE_ISSINGLE">
                <el-radio label="单次"></el-radio>
                <el-radio label="累计"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="网络内免赔额">
              <el-input v-model="INTEREST_PRODUCE.INTEREST_PRODUCE_MPN" placeholder="网络内免赔额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="网络外免赔额">
              <el-input v-model="INTEREST_PRODUCE.INTEREST_PRODUCE_MPW" placeholder="网络外免赔额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      <!-- 医疗责任分项责任 -->
          <el-card :key='duty.IP_DUTY_NAME'  v-for="duty in dutyList">
           <div slot="header" class="clearfix">
            <span style="line-height: 36px;">{{duty.showName}}</span>         
        </div>
         <el-row>
          <el-col :span="12">
            <el-form-item label="分类保险责任给付限额">
              <el-input v-model="duty.IP_DUTY_MAXMONEY" placeholder="分类保险责任给付限额"></el-input>
            </el-form-item>            
          </el-col>
           </el-row>
           <!-- 分項詳情 -->
            <el-row :key="item.IP_ITEM_ID" v-for="item in duty.IP_ITEM">
              
        <el-col :span="24">
    <el-collapse >
  <el-collapse-item :title="item.showname" >
    <el-form :model="item"  label-width="140px"  :inline="true" class="demo-ruleForm">
    <el-form-item label="单次自付额内"   >
    <el-input v-model="item.IP_ITEM_ZFEN"></el-input>
  </el-form-item>
  <el-form-item label="单次自付额外"    >
    <el-input v-model="item.IP_ITEM_ZFEW"></el-input>
  </el-form-item>  
  <el-form-item label="单项给付比例内(%)"
   >
    <el-input v-model="item.IP_ITEM_ZFBLN"></el-input>
  </el-form-item>
   <el-form-item label="单项给付比例外(%)"
   >
    <el-input v-model="item.IP_ITEM_ZFBLW"></el-input>
  </el-form-item> 
   <el-form-item label="给付限额内"
   >
    <el-input v-model="item.IP_ITEM_MAXM"></el-input>
  </el-form-item>
   <el-form-item label="给付限额外" >
    <el-input v-model="item.IP_ITEM_MAXMW"></el-input>
  </el-form-item>  
    <el-form-item label="是否是每日"   >
     <el-radio-group v-model="item.IP_ITEM_ISPER" >
      <el-radio label="是"></el-radio>
      <el-radio label="否"></el-radio>
    </el-radio-group> 
  </el-form-item>
    <el-form-item label="给付期限"  :prop="'IP_ITEM_MAXDAY'">
    <el-input v-model="item.IP_ITEM_MAXDAY"></el-input>
  </el-form-item>    
   </el-form> 
  </el-collapse-item>
          </el-collapse>
         
          </el-col>
            </el-row>
              <!-- 分項詳情 -->
          </el-card>   
                  <!-- 结束 医疗责任分项责任 -->
            </el-form>
      </el-card>

<div :key="item.IPOTHER_ID" v-for="item in otherModel ">
 <el-card  v-if="GetShow(item.IPOTHER_NAME)">
           <div slot="header" class="clearfix">
            <span style="line-height: 36px;">{{item.IPOTHER_NAME}}</span>     
             <el-input style="  width: 150px; margin-left: 50px;" v-model="item.IPOTHER_MONEY" placeholder="保险金额"></el-input>     
        </div>
        <el-row>           
  </el-row>
         <el-form :model="item"  label-width="140px"   :inline="true" class="demo-ruleForm"> 
  
           <el-row :key="data.IPOTHER_ITEM_ID" v-for="data in item.IPOTHER_ITEM">   
              <el-col :span="3">  
              <el-form-item :label="data.IPOTHER_ITEM_NAME" label-width="250">
              </el-form-item>  
              </el-col>
                                      
                   <el-form-item label="单次自付额" v-if="item.IPOTHER_NAME=='全球紧急救援保险责任'">
                      <el-input v-model="data.IPOTHER_ITEM_ZFMONEY" placeholder="单次自付额"></el-input>
             </el-form-item>                      
               <el-form-item label="单项自付比例(%)"  v-if="item.IPOTHER_NAME=='全球紧急救援保险责任'">
               <el-input v-model="data.IPOTHER_ITEM_ZFBL" placeholder="单项自付比例"></el-input>
                 </el-form-item>
                   <el-form-item label="单项给付限额">
                      <el-input v-model="data.IPOTHER_ITEM_MONEY" placeholder="单项给付限额"></el-input>
               </el-form-item>  
           </el-row>   
  
         </el-form>
        
      </el-card>
</div>
<div style="margin-top:20px; text-align:center">
<el-button type="primary" @click="add" v-if="!IsHave">
  新增
</el-button>
<el-button type="primary" v-else @click="change">
  修改
</el-button>
</div>
  </div> 

</template>

<script>
import api from "@/js/api";
import getid from "@/js/getid";
export default {
  data() {
    return {
      IsHave: false, //是新增还是修改
      INTEREST_PRODUCE: {
        INTEREST_PRODUCE_ID: "",
        INTEREST_PRODUCE_NAME: "",
        INTEREST_PRODUCE_MAXMONEY: "",
        INTEREST_PRODUCE_ZFMAX: "",
        INTEREST_PRODUCE_ISSINGLE: "",
        INTEREST_PRODUCE_MPN: "",
        INTEREST_PRODUCE_MPW: "",
        IP_DUTY: []
      },
      INTEREST_ORDEROTHER: [],
      //医疗责任 分项
      dutyList: [
        {
          IP_DUTY_ID: "",
          IP_DUTY_NAME: "201705110922193613",
          showName: "住院保险责任",
          IP_DUTY_MAXMONEY: "",
          DUTYITEM_ID: "201705110922193613",
          INTEREST_PRODUCE_ID: "",
          IP_ITEM: []
        },
        {
          IP_DUTY_ID: "",
          IP_DUTY_NAME: "201705101750538838",
          showName: "门（急）诊保险责任",
          IP_DUTY_MAXMONEY: "",
          DUTYITEM_ID: "201705101750538838",
          INTEREST_PRODUCE_ID: "",
          IP_ITEM: []
        },
        {
          IP_DUTY_ID: "",
          IP_DUTY_NAME: "201705101751543483",
          showName: "特殊医疗保险责任",
          IP_DUTY_MAXMONEY: "",
          DUTYITEM_ID: "201705101751543483",
          INTEREST_PRODUCE_ID: "",
          IP_ITEM: []
        }
      ],
      //其他类型保险责任
      otherModel: []
    };
  },
  props: {
    type: {
      type: String,
      default: ""
    },
    Id: {
      type: String,
      default: ""
    }
  },
  methods: {
    GetShow(name) {
      if (this.type == "安心") {
        return false;
      }
      if (this.type == "周详" && name == "意外伤害保险责任") {
        return true;
      }
      if (this.type == "畅游") {
        return true;
      }
    },
    //新增 
    GetItem(value) {
      for (let i = 0; i < this.dutyList.length; i++) {
        this.dutyList[i].IP_DUTY_ID = getid.getid();
        for (let k = 0; k < value.length; k++) {
          if (value[k].DUTYITEM_FID == this.dutyList[i].IP_DUTY_NAME) {
            var ipItem = {
              IP_ITEM_ID: getid.getid(),
              IP_ITEM_ZFBLN: "",
              IP_ITEM_ZFBLW: "",
              IP_ITEM_ZFEN: "",
              IP_ITEM_ZFEW: "",
              IP_ITEM_MAXM: "",
              IP_ITEM_ISPER: "",
              IP_ITEM_MAXDAY: "",
              IP_DUTY_ID: this.dutyList[i].IP_DUTY_ID, //分项id
              DUTYITEM_ID: value[k].DUTYITEM_ID, //责任id
              IP_ITEM_MAXMW: "",
              showname: value[k].DUTYITEM_NAME
            };
            this.dutyList[i].IP_ITEM.push(ipItem);
          }
        }
      }
    },
    add() {
      this.INTEREST_PRODUCE.INTEREST_PRODUCE_ID = getid.getid();
      this.INTEREST_PRODUCE.INTEREST_PRODUCE_NAME = this.Id;
      this.INTEREST_PRODUCE.IP_DUTY = this.dutyList;
      this.INTEREST_ORDEROTHER = this.otherModel;
      var data = {
        INTEREST_PRODUCE: this.INTEREST_PRODUCE,
        INTEREST_ORDEROTHER: this.INTEREST_ORDEROTHER
      };
      // console.log(data);
      api.BenifitAdd(this, data);
    },
    //根据 类型id和名称进行匹配
    dataItem(value) {
      // console.log("22");
      for (var i = 0; i < this.dutyList.length; i++) {
        //
         for (var l = 0; l < value.length; l++) {
        for (var k = 0; k < this.dutyList[i].IP_ITEM.length; k++) {
          //         
            if (
              value[l].DUTYITEM_ID == this.dutyList[i].IP_ITEM[k].DUTYITEM_ID
            ) {
              this.dutyList[i].IP_ITEM[k].showname = value[l].DUTYITEM_NAME;              
            } 
        }      
        if(this.dutyList[i].showName=='特殊医疗保险责任' && this.dutyList[i].IP_ITEM.length!=17 && (value[l].DUTYITEM_NAME=='精神疾病和行为障碍医疗费' || value[l].DUTYITEM_NAME=='预防保健费' ||  value[l].DUTYITEM_NAME=='生育医疗费'))  {     
          
          
          var ipItem = {
              IP_ITEM_ID: getid.getid(),
              IP_ITEM_ZFBLN: "",
              IP_ITEM_ZFBLW: "",
              IP_ITEM_ZFEN: "",
              IP_ITEM_ZFEW: "",
              IP_ITEM_MAXM: "",
              IP_ITEM_ISPER: "",
              IP_ITEM_MAXDAY: "",
              IP_DUTY_ID: this.dutyList[i].IP_DUTY_ID, //分项id
              DUTYITEM_ID: value[l].DUTYITEM_ID, //责任id
              IP_ITEM_MAXMW: "",
              showname: value[l].DUTYITEM_NAME
            };
            this.dutyList[i].IP_ITEM.push(ipItem);
               console.log(this.dutyList[i].IP_ITEM);
           
        }
    
         }
      }
    },
    change() {
      this.INTEREST_PRODUCE.IP_DUTY = this.dutyList;
      this.INTEREST_ORDEROTHER = this.otherModel;
      var data = {
        INTEREST_PRODUCE: this.INTEREST_PRODUCE,
        INTEREST_ORDEROTHER: this.INTEREST_ORDEROTHER
      };
      api.BenfitUpdate(this, data);
    },
    //获取数据 如果为空 将Ishave 修改成fasle
    getData() {},
    otherDate() {
      console.log(this.type)
      if (this.type == "安心") {
        return;
      }
      if (this.type == "周详") {
        this.otherModel = [
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "意外伤害保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "意外伤残/身故",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          }
        ];
      }
      if (this.type == "畅游") {
        this.otherModel = [
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "意外伤害保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "意外伤残/身故",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          },
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "全球紧急救援保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "紧急医疗救援费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "紧急转院费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "紧急运返费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "紧急转院或运返陪同费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
               {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "家属境外慰问探访费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "遗体运返或安葬费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "遗体转送回国费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "灵柩费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "火葬和运送骨灰回国费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },

              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "骨灰盒费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "就地安葬费",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          },
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "学业中断保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "学业中断",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          },
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "旅行不便保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "旅行延误",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "旅行证件遗失",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              },
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "随身财产损失或丢失",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          },
          {
            IPOTHER_ID: "",
            IPOTHER_NAME: "个人第三者保险责任",
            IPOTHER_MONEY: "",
            PRODUCTNO: "",
            IPOTHER_ITEM: [
              {
                IPOTHER_ITEM_ID: "",
                IPOTHER_ITEM_NAME: "个人第三者责任",
                IPOTHER_ITEM_MONEY: "",
                IPOTHER_ITEM_ZFMONEY: "",
                IPOTHER_ITEM_ZFBL: "",
                IPOTHER_ID: ""
              }
            ]
          }
        ];
      }
    }
  },
  created() {
    console.log(this.type);
    let that = this;
    var result;
    var data = {
      Id: this.Id
    };
    api.BenfitGet(that, data, function(msg) {
      //更新数据 如果有数据 既是修改
      if (msg.Result.INTEREST_PRODUCE) {
        that.IsHave = true;
        var re = msg.Result;       
        var obj = re.INTEREST_PRODUCE;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_ID = obj.INTEREST_PRODUCE_ID;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_NAME = obj.INTEREST_PRODUCE_NAME;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_MAXMONEY =
          obj.INTEREST_PRODUCE_MAXMONEY;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_ZFMAX =
          obj.INTEREST_PRODUCE_ZFMAX;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_ISSINGLE =
          obj.INTEREST_PRODUCE_ISSINGLE;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_MPN = obj.INTEREST_PRODUCE_MPN;
        that.INTEREST_PRODUCE.INTEREST_PRODUCE_MPW = obj.INTEREST_PRODUCE_MPW;

         //所有 item项
        var item = re.INTEREST_PRODUCE.IP_DUTY;
        for (var i = 0; i < item.length; i++) {
          //增加showname属性 否则 无法双向绑定
          for (var l = 0; l < item[i].IP_ITEM.length; l++) {
            item[i].IP_ITEM[l].showname = "";
          }
          //将 获取的数据赋值给 责任列表
          for (var k = 0; k < that.dutyList.length; k++) {
            if (
              that.dutyList[k].DUTYITEM_ID ==
              item[i].DUTYITEM_ID
            ) {
              that.dutyList[k].IP_DUTY_ID = item[i].IP_DUTY_ID;
              that.dutyList[k].IP_DUTY_MAXMONEY = item[i].IP_DUTY_MAXMONEY;
              that.dutyList[k].INTEREST_PRODUCE_ID =
                item[i].INTEREST_PRODUCE_ID;
              that.dutyList[k].IP_ITEM = item[i].IP_ITEM;
            }
          }
        }
        //将责任详情名称 赋值给责任详情
        api.IP_ITEMGetAll(that, function(msg) {
          result = msg.Result;
          that.dataItem(result);
          // that.GetItem(msg.Result);
        });
        if (msg.Result.INTEREST_ORDEROTHER.length > 0) {
          that.otherModel = msg.Result.INTEREST_ORDEROTHER;
          console.log(that.type=="周详")
          console.log(that.otherModel);       
        }
      } else {
        //没有数据 新增
        //初始化其他责任类型
        that.otherDate();
        api.IP_ITEMGetAll(that, function(msg) {
          result = msg.Result;
          that.GetItem(msg.Result);
        });
        //初始化 其他类型责任
        var model = that.otherModel;

        for (var i = 0; i < model.length; i++) {
          model[i].IPOTHER_ID = getid.getid();
          var item = model[i].IPOTHER_ITEM;
          model[i].PRODUCTNO = that.Id;
          for (var k = 0; k < item.length; k++) {
            item[k].IPOTHER_ITEM_ID = getid.getid();
            item[k].IPOTHER_ID = model[i].IPOTHER_ID;
          }
        }
      }
    });
  }
};
</script>

<style scoped>
.el-card {
  margin-top: 20px;
}
</style>
